<template>
  <div>
    <el-form :inline="true" :model="dataForm">
      <el-form-item>
        <el-input v-model="dataForm.appName" placeholder="应用名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.formName" placeholder="表单名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="getFormList()">查询</el-button>
        <el-button type="primary" @click="addInfoHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="tableData"
      row-key="formList"
      border size="mini"
      height="350px"
      style="width: 100%;">
      <el-table-column fixed="left" prop="appName" label="应用名称" min-width="150">
      </el-table-column>
      <el-table-column fixed="left" prop="formName" label="表单名称" min-width="150">
      </el-table-column>
      <el-table-column fixed="left" prop="tableName" label="表名" min-width="100">
      </el-table-column>
      <el-table-column fixed="left" prop="moudleName" label="模块名称" min-width="200">
      </el-table-column>
      <el-table-column prop="isDel" align="center" label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.isDel == 0">正常</span>
          <span v-else-if="scope.row.isDel == 1">失效</span>
        </template>
      </el-table-column>

      <el-table-column prop="id" header-align="center" align="center" width="200" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="formInfoHandle(scope.row.formId)">详情</el-button>
          <el-button type="text" size="small" @click="editInfoHandle(scope.row.formId)">编辑</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.formId)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页信息 -->
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="total"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!--弹窗-->
    <addInfo v-if="addVisible" ref="addInfo" @refreshDataList="getFormList"></addInfo>

  </div>
</template>

<script>
  import AddInfo from './addForm'

  export default {
    name: 'moudleBase',
    data () {
      return {
        tableData: [],
        dataForm: {
          appName: '',
          formName: ''
        },
        addVisible: false,
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        total: 0
      }
    },
    components: {
      AddInfo
    },
    activated () {
      this.init()
    },
    methods: {
      init () {
        this.$nextTick(() => {
          this.getFormList()
        })
      },
      getFormList () {
        this.tableData = []
        let pageParam = {
          'pageNumber': this.pageIndex,
          'pageSize': this.pageSize
        }
        var param = { ...pageParam, ...this.dataForm }
        this.$http({
          url: this.$http.adornUrl('/form/formBaseList'),
          method: 'post',
          params: this.$http.adornParams(param, false)
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.tableData = data.data.data
            this.totalPage = data.data.pages
            this.total = data.data.total
          } else {
            this.tableData = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        }, false)
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getStudyCardList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getStudyCardList()
      },
      addInfoHandle () {
        this.addVisible = true
        this.$nextTick(() => {
          this.$refs.addInfo.init()
        })
      },
      formInfoHandle (id) {
        this.addVisible = true
        this.$nextTick(() => {
          this.$refs.addInfo.init(id)
        })
      },
      editInfoHandle (id) {
        this.addVisible = true
        this.$nextTick(() => {
          this.$refs.addInfo.init(id)
        })
      },
      deleteHandle (id) {
        this.addVisible = true
        this.$nextTick(() => {
          this.$refs.addInfo.init(id)
        })
      }
    }
  }
</script>

<style scoped>

</style>
